package com.example.yunyuapp;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;


public class PM2_5RVAdapter extends RecyclerView.Adapter<PM2_5RVAdapter.ViewHolder> {
    PM2_5TOP pm2_5TOP;

    public PM2_5RVAdapter(PM2_5TOP pm2_5TOP) {
        this.pm2_5TOP = pm2_5TOP;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemNum, tvItemArea, tvItemPM25, tvItemAQI, tvItemQuality;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemNum = itemView.findViewById(R.id.tvItemNum);
            tvItemArea = itemView.findViewById(R.id.tvItemArea);
            tvItemPM25 = itemView.findViewById(R.id.tvItemPM25);
            tvItemAQI = itemView.findViewById(R.id.tvItemAQI);
            tvItemQuality = itemView.findViewById(R.id.tvItemQuality);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_item_rank, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvItemNum.setText(pm2_5TOP.getShowapi_res_body().getList().get(position).getNum());
        holder.tvItemArea.setText(pm2_5TOP.getShowapi_res_body().getList().get(position).getArea());
        holder.tvItemPM25.setText(pm2_5TOP.getShowapi_res_body().getList().get(position).getPm2_5());
        holder.tvItemAQI.setText(pm2_5TOP.getShowapi_res_body().getList().get(position).getAqi());
        holder.tvItemQuality.setText(pm2_5TOP.getShowapi_res_body().getList().get(position).getQuality());
    }

    @Override
    public int getItemCount() {
        return pm2_5TOP.getShowapi_res_body().getList().size();
    }
}
